home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group99a.txt
/
000074_icon-group-sender _Wed Mar 31 09:27:26 1999.msg
< prev
next >
Wrap
Internet Message Format
|
2000-09-20
|
6KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id JAA09430
for icon-group-addresses; Wed, 31 Mar 1999 09:27:18 -0700 (MST)
Message-Id: <199903311627.JAA09430@baskerville.CS.Arizona.EDU>
Date: Wed, 31 Mar 1999 00:13:29 -0400 (AST)
From: Larry Bezeau <bezeau@unb.ca>
X-Sender: bezeau@sol.sun.csd.unb.ca
To: Icon list <icon-group@optima.CS.Arizona.EDU>
Subject: Re: Problem reading binary file
Errors-To: icon-group-errors@optima.CS.Arizona.EDU
Status: RO
Steve,
>I am using MS-DOS Icon 9.1 to read a binary file. After reading 6
>characters, the program apparently quits reading. I have attached the
>relevant portion of the code:
>
I encountered this problem myself sometime ago. To overcome
it you must open the file in unstranslated mode as shown below.
Note the "u" in the open statement. A "t" in the same position means
translated but this is the default if neither is specified.
in := open(args[1],"ru") | stop("Unable to open ",args[1])
This will allow your program to read the file character by character
without having to worry about whether the character is an end of file
character or a line-ending character. In general, if you are reading
a file with reads, it should be opened in untranslated mode and if
you are reading it with read it should be opened in translated mode.
To put it another way, if the file is being used as a text file it
should be opened in translated mode but if it is being used as a
binary file it should be opened in untranslated mode.
Larry Bezeau@UNB.Ca
>-------------------------- Code ------------------------------
>procedure main(args)
>#
> cnt := 0
> out := open(args[2],"w") | stop("Unable to open ",args[2])
> while character := reads(in,1) do {
> write(character," -->", ord(character))
> cnt := cnt+1
> }
> close(in,out)
> write(cnt," characters transferred")
>end
>-----------------------End of Code-------------------------
>
>I invoke the program with:
>
>word r99-0059.doc r99-0059.txt
>
>
>I get output of (some unprintable characters are represent by _):
>
>- -->208
>- -->207
> -->17
>_ -->224
>� -->161
>_ -->177
>6 characters transferred
>
>
>Any ideas?
>
>Thanks in advance.
>
>
>-- Steve
>
>
>______________________________________________________
>
>Steve Graham
>Laboratory Corporation of America (LabCorp)
>12160 Abrams Road, Suite 601
>Dallas, Texas 75243
>
>E-mail: graham@cowboy.biomed.com
>Phone: 972.643.6124 (direct to desk)
> 972.437.5255 ext 5224
>FAX: 972.454.1040
>_______________________________________________________
>
>From icon-group-sender@baskerville.CS.Arizona.EDU Tue Mar 30 18:42:50 1999
>Date: Tue, 30 Mar 1999 16:04:23 -0600
>From: Steve Graham <graham@cowboy.biomed.com>
>Subject: [Fwd: Problem reading binary file]
>Status: O
>X-Status:
>X-Keywords:
>X-UID: 2
>
>Hello again.
>
>Turns out that the problem with this was that the 7th character was an
>ASCII 26 (^Z) and Icon would not read any further than that. I created
>a 2nd file with a ^Z in a different position and got a similar result.
>This is despite the fact that there were over 25,000 characters
>following the Control Z.
>
>So, my question is: Why does Icon stop reading when it hits a ^Z? I
>can kind of understand this if I were reading a text file; but I was
>specifically using reads() because this is a binary file? Should not
>reads() support all 256 ASCII codes and only stop reading when there are
>REALLY no more characters to read? I ended up using another language,
>which was significantly harder for me, to read the binary characters.
>
>In Icon's defense, I notice that when I TYPE the above-mentioned 2nd
>file, I only see the characters occurring prior to the ^Z. And I do not
>want it to appear that I am questioning Icon's usefulness. It is
>normally one of the 1st languages I choose for utilities of this type.
>
>Comments?
>
>
>Steve Graham
>
>===
>
>Steve Graham wrote:
>>
>> Hello.
>>
>> I am using MS-DOS Icon 9.1 to read a binary file. After reading 6
>> characters, the program apparently quits reading. I have attached the
>> relevant portion of the code:
>>
>> -------------------------- Code ------------------------------
>> procedure main(args)
>> #
>> cnt := 0
>> in := open(args[1],"r") | stop("Unable to open ",args[1])
>> out := open(args[2],"w") | stop("Unable to open ",args[2])
>> while character := reads(in,1) do {
>> write(character," -->", ord(character))
>> cnt := cnt+1
>> }
>> close(in,out)
>> write(cnt," characters transferred")
>> end
>> -----------------------End of Code-------------------------
>>
>> I invoke the program with:
>>
>> word r99-0059.doc r99-0059.txt
>>
>> I get output of (some unprintable characters are represent by _):
>>
>> - -->208
>> - -->207
>> -->17
>> _ -->224
>> � -->161
>> _ -->177
>> 6 characters transferred
>>
>> Any ideas?
>>
>> Thanks in advance.
>>
>> -- Steve
>>
>> ______________________________________________________
>>
>> Steve Graham
>> Laboratory Corporation of America (LabCorp)
>> 12160 Abrams Road, Suite 601
>> Dallas, Texas 75243
>>
>> E-mail: graham@cowboy.biomed.com
>> Phone: 972.643.6124 (direct to desk)
>> 972.437.5255 ext 5224
>> FAX: 972.454.1040
>> _______________________________________________________
>